import Vue from "vue";
import Router from "vue-router";
import Login from "../components/Login";
import Detail from "../components/Detail";
import Index from "../components/Index/Index.vue";
import Stats from "../components/Stats/Stats.vue";
import wmsList from "../components/wms/wmsList.vue";
import wmsEch from "../components/wms/wmsEch.vue";
import userList from "../components/user/userList.vue";
import Wms from "../components/Wms.vue";
import User from "../components/User.vue";

Vue.use(Router);

const router = new Router({
    routes: [
        {
            path: '/', redirect: '/login'
        },
        {
            path: "/login",
            name: "Login",
            component: Login,
            meta: { title: '登录' }
        },
        // 一级路由
        {
            path: "/detail",
            name: "Detail",
            component: Detail,
            redirect: "/Index",
            meta: { title: '首页' },
            // 二级路由：在首页下面展示，并没有跳转到一个新的页面
            children: [
                {
                    path: "/Index",
                    name: "Index",
                    component: Index,
                    meta: { title: '首页' }
                },
                {
                    path: "/Stats",
                    name: "Stats",
                    component: Stats,
                    meta: { title: '数据统计' }
                },
                {
                    path: "/wms",
                    name: "Wms",
                    component: Wms,
                    meta: { title: '信息管理' },
                    children: [
                        {
                            path: "/wms/list",
                            name: "wmsList",
                            component: wmsList,
                            meta: { title: '列表展示' }

                        },
                        {
                            path: "/wms/ech",
                            name: "wmsEch",
                            component: wmsEch,
                            meta: { title: '图标展示' }

                        },
                    ]
                },
                {
                    path: "/user",
                    name: "User",
                    component: User,
                    meta: { title: '用户管理' },
                    children: [
                        {
                            path: "/user/list",
                            name: "userList",
                            component: userList,
                            meta: { title: '用户统计' }

                        },
                    ]
                }
            ]
        }
    ],

})
// 路由拦截
router.beforeEach((to, from, next) => {
    if (!sessionStorage.getItem('userName')) {
        if (to.path !== '/login') {
            next('/login')
        }
    }
    next()
})
export default router

